package shared;

import java.sql.*;

public class Data {
	public Connection createConnection(){
		Connection conn = null;
		
		try{
			String username = "article_user";
			String password = "article_user";
			String url = "jdbc:mysql://localhost:3306/articles";
			Class.forName("com.mysql.jdbc.Driver").newInstance();
			conn = DriverManager.getConnection(url,username,password);
		}
		catch (Exception e){}
		finally{}
		
		return conn;
	}
	
	public void saveKeyword(String word){
		try{
			
			Connection conn = createConnection();
			Statement s = conn.createStatement();
			s.executeUpdate("INSERT INTO keyword(word) VALUES('" + word + "')");
			s.close();
			conn.close();
		}
		catch(Exception e){}
		finally{}
	}
	
	public ResultSet getKeywords(){
		ResultSet rs = null;
		try{
			Connection conn = createConnection();
			Statement s = conn.createStatement();
			s.executeQuery("SELECT id, word FROM keyword");
			rs = s.getResultSet();
			s.close();
			conn.close();
		}
		catch(Exception e){}
		finally{}
		
		return rs;
	}
}
